package com.abc.robot01.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.fragment.findNavController
import com.abc.robot01.R
import com.abc.robot01.activity.MyButton01
import com.abc.robot01.activity.px
import com.abc.robot01.databinding.Fragment03Binding

/**
 * 首页配置
 */
class HomeConfigFragment : Fragment() {

    private var _binding: Fragment03Binding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val composeView = ComposeView(requireContext()).apply {
            setContent {
                val textState = remember { mutableStateOf("") }
                Box(
                    modifier = Modifier.fillMaxSize()
                ) {
                    // 背景图片
                    Image(
                        painter = painterResource(id = R.drawable.z1), // 替换为你的图片资源ID
                        contentDescription = null,
                        contentScale = ContentScale.Crop, // 使图片填充整个背景
                        modifier = Modifier.matchParentSize() // 使图片铺满整个Box
                    )
                    MyButton01(modifier=Modifier.align(Alignment.Center).offset(y= (-25).dp),text = "刷新首页配置", containerColor = Color.Blue,size =  DpSize(380.dp/3.5f,70.dp/3.5f)){
                      refresh()
              }
              }
            }
        }

        return  composeView
        // Return the ComposeView as the root view of the fragment
//        return composeView
//        _binding = Fragment03Binding.inflate(inflater, container, false)
//        return binding.root

    }

    private fun refresh() {
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

//        binding.button03.setOnClickListener {
//            findNavController().navigate(R.id.action_Fragment03_to_FirstFragment)
//        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
//        _binding = null
    }

private fun edit(id:Int){
//    startActivity<>()
}

    private fun delete(id:Int){
//    startActivity<>()
    }

}

